# utils/response.py
from flask import jsonify

class ResponseUtil:
    """统一响应工具类"""

    @staticmethod
    def success(data=None, message="成功"):
        """成功响应"""
        return jsonify({
            "code": 200,
            "data": data,
            "msg": message
        }), 200

    @staticmethod
    def error(code=1008, message="登录失败", data=None):
        """错误响应"""
        return jsonify({
            "code": code,
            "data": data,
            "msg": message
        }), 200  # HTTP状态码保持200，业务状态码用code字段

    @staticmethod
    def unauthorized(message="未授权"):
        """未授权响应"""
        return jsonify({
            "code": 401,
            "data": None,
            "msg": message
        }), 200
